import { Client } from "src/modules/client/client.entity";
import { Company } from "src/modules/company/company.entity";
import { DeliveryItem } from "src/modules/delivery-item/delivery-item.entity";
import { User } from "src/modules/user/user.entity";
import {
  Column,
  CreateDateColumn,
  Entity,
  ManyToOne,
  OneToMany,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
} from "typeorm";

@Entity()
export class Delivery {
  @PrimaryGeneratedColumn("uuid")
  id: string;

  @ManyToOne(() => User, (user) => user.deliveries, { nullable: false })
  user: User;

  @ManyToOne(() => Company, (company) => company.deliveries, {
    nullable: false,
  })
  company: Company;

  @ManyToOne(() => Client, (client) => client.deliveries, { nullable: false })
  client: Client;

  @OneToMany(() => DeliveryItem, (deliveryItem) => deliveryItem.delivery)
  deliveryItems: DeliveryItem[];

  @CreateDateColumn()
  date: Date;

  @UpdateDateColumn()
  update: Date;

  // 唯一对外指定暴露送货单ID
  @Column()
  no: string;

  @Column({ default: "" })
  address: string;

  @Column({ default: "" })
  contact: string;

  @Column()
  deliveryDate: Date;
}
